var __extends =
    (this && this.__extends) ||
    (function () {
      var t = function (e, i) {
        return (t =
          Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array &&
            function (t, e) {
              t.__proto__ = e;
            }) ||
          function (t, e) {
            for (var i in e)
              Object.prototype.hasOwnProperty.call(e, i) && (t[i] = e[i]);
          })(e, i);
      };
      return function (e, i) {
        function n() {
          this.constructor = e;
        }
        if ("function" != typeof i && null !== i)
          throw new TypeError(
            "Class extends value " + String(i) + " is not a constructor or null"
          );
        t(e, i),
          (e.prototype =
            null === i
              ? Object.create(i)
              : ((n.prototype = i.prototype), new n()));
      };
    })(),
  AXTaoYuanListDialog = (function (t) {
    function e() {
      var e = t.call(this) || this;
      return (
        (e.list_select_item.vScrollBarSkin = ""),
        (e.list_select_item.selectEnable = !0),
        e.list_select_item.on(Laya.Event.CLICK, e, e.onSelectDidClick),
        (e.list_select_item.renderHandler = new Handler(e, e.updateItem)),
        e.btn_quit.on(Laya.Event.CLICK, e, e.onQuitBtn),
        e.btn_end.on(Laya.Event.CLICK, e, e.onEndBtn),
        e.btn_start.on(Laya.Event.CLICK, e, e.onStartBtn),
        WebSocketService.addListener({
          caller: e,
          code: 13651,
          method: e.onLoadListData,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 1365,
          method: e.onQiuhun,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 13423,
          method: e.onLoadJieyiListData,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 1363,
          method: e.onJieyi,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 1342,
          method: e.onQiuhun,
        }),
        Laya.stage.on("AXTaoYuanListDialog", e, e.eventHandler),
        e
      );
    }
    return (
      __extends(e, t),
      (e.showDialog = function (t, i) {
        null == this.instance && (this.instance = new e()),
          (this.instance.list_select_item.dataSource = []),
          1 == t &&
            ((this.instance.btn_quit.visible = !1),
            (this.instance.btn_start.visible = !1),
            (this.instance.btn_end.visible = !1),
            (this.instance.label_title.text = "永结同心"),
            (this.instance.label_hint.text = "选择伴侣："),
            (this.instance.label_num.text = ""),
            WebSocketService.send({ c: 13651, d: { pageNum: 0 } })),
          2 == t &&
            ((this.instance.label_title.text = "义结金兰"),
            (this.instance.label_title.text = "选择基友："),
            (this.instance.label_num.text = "（0/5）"),
            WebSocketService.send({ c: 13423, d: { mateId: i, pageNum: 0 } })),
          (this.instance.type = t),
          this.instance.popup();
      }),
      (e.prototype.onSelectDidClick = function (t) {
        if ("btn_sel" == t.target.name) {
          var e = t.currentTarget.selectedItem;
          1 == this.type &&
            WebSocketService.send({ c: 1365, d: { roleId: e.roleId } }),
            2 == this.type &&
              WebSocketService.send({ c: 1363, d: { roleId: e.roleId } });
        }
      }),
      (e.prototype.onLoadListData = function (t) {
        if (0 == t.code) {
          var e = t.list;
          this.dataSource = [];
          for (var i = 0; i < e.length; i++) {
            var n = e[i],
              o = {
                label_i: { text: i + 1 + "." },
                label_name: { text: n.userName },
                label_hao: { text: n.hyd + "好友度" },
                btn_sel: { label: "选择" },
                roleId: n.roleId,
                state: 0,
              };
            this.dataSource.push(o);
          }
          this.list_select_item.dataSource = this.dataSource;
        } else ToastView.toastView(t.msg);
      }),
      (e.prototype.onLoadJieyiListData = function (t) {
        if (0 == t.code) {
          var e = t.data;
          e.roleId == e.roleId
            ? ((this.btn_quit.visible = !1),
              (this.btn_start.visible = !0),
              (this.btn_end.visible = !0))
            : ((this.btn_quit.visible = !0),
              (this.btn_start.visible = !1),
              (this.btn_end.visible = !1));
          var i = e.mateList;
          this.label_num.text = "（" + i.length + "/5）";
          for (var n = [], o = 0; o < i.length; o++) {
            r = {
              label_i: { text: o + 1 + "." },
              label_name: { text: (s = i[o]).userName },
              label_hao: { text: "" },
              btn_sel: { label: "已加入" },
              roleId: s.roleId,
              state: 1,
            };
            n.push(r);
          }
          if (e.yqList)
            for (var a = e.yqList, l = 0; l < a.length; l++) {
              var s = a[l];
              if (!this.containRoleId(i, s.roleId)) {
                var r = {
                  label_i: { text: o + 1 + "." },
                  label_name: { text: s.userName },
                  label_hao: { text: s.hyd + "好友度" },
                  btn_sel: { label: "邀请" },
                  roleId: s.roleId,
                  state: 0,
                };
                n.push(r), o++;
              }
            }
          this.list_select_item.dataSource = n;
        } else ToastView.toastView(t.msg);
      }),
      (e.prototype.containRoleId = function (t, e) {
        for (var i = 0; i < t.length; i++) {
          if (t[i].roleId == e) return !0;
        }
        return !1;
      }),
      (e.prototype.updateItem = function (t, e) {
        var i = t.getChildByName("btn_sel"),
          n = t.dataSource;
        if (1 == n.state && ((i.disabled = !0), Global.roleId == n.roleId)) {
          t.getChildByName("label_name").text = "我";
        }
      }),
      (e.prototype.onQuitBtn = function () {
        AXTaoYuanSureDialog.showDialog({
          title: "义结金兰",
          msg: "你确定要退出结拜吗？",
          from: "AXTaoYuanListDialog",
          code: "quit",
          okText: "确定",
        });
      }),
      (e.prototype.onEndBtn = function () {
        AXTaoYuanSureDialog.showDialog({
          title: "义结金兰",
          msg: "你确定要终止结拜吗？",
          from: "AXTaoYuanListDialog",
          code: "end",
          okText: "确定",
        });
      }),
      (e.prototype.onStartBtn = function () {
        AXTaoYuanSureDialog.showDialog({
          title: "义结金兰",
          msg: "你确定要开始结拜吗？",
          from: "AXTaoYuanListDialog",
          code: "start",
          okText: "确定",
        });
      }),
      (e.prototype.onQiuhun = function (t) {
        ToastView.toastView(t.msg),
          0 == t.code && (WebSocketService.send({ c: 1333 }), this.close());
      }),
      (e.prototype.onJieyi = function (t) {
        ToastView.toastView(t.msg);
      }),
      (e.prototype.eventHandler = function (t) {
        t &&
          ("quit" == t && WebSocketService.send({ c: 1342, d: { type: 23 } }),
          "end" == t && WebSocketService.send({ c: 1342, d: { type: 13 } }),
          "start" == t && WebSocketService.send({ c: 1342, d: { type: 9 } }));
      }),
      e
    );
  })(ui.SquareController.AXTaoYuanListDialogUI);
